<template>
	<view class="activity-list-wrapper" @click="detail" v-if="Object.keys(info) != false">
		<view class="tag" :class="{'tag-gray': (info?.status > 3 && info?.status < 7) || info?.status == 8}" >
			{{ statusFormat(info?.status, info.enroll_date_start, info.enroll_date_end) }}
		</view>
		<view class="main-info">
			<view class="left">
				<image class="left_img" :src="info.imgs?.split(',').at(0)" mode="aspectFill" lazy-load></image>
			</view>
			<view class="right">
				<view class="right-top">
					<view class="title">{{info?.title || ''}}</view>
					<view class="right-item location-info">
						<!-- <uni-icons type="location" :size="20" color="#999"></uni-icons> -->
						<image class="icon-img" src="../../static/icons/location.svg" mode="aspectFill"></image>
						<view class="name">{{info?.address || '不限'}}</view>
					</view>
					<view class="right-item time-wrapper">
						<image class="icon-img" src="../../static/icons/time.svg" mode="aspectFill"></image>
						<view class="name time-text">
							{{ activityDateFormat(info.activity_date_start, info.activity_date_end) }}
						</view>
					</view>
				</view>
				
				<!-- 用户信息 -->
				<view class="right-item user-info">
					<image class="avatar" :src="info?.user_info?.avatar || '/static/images/logo.png'" mode="aspectFill"></image>
					<view class="name">{{info?.user_info?.name || ''}}</view>
					<image class="shop-auth" src="/static/icons/shop-auth.svg" mode="" v-if="info.user_info &&  info.user_info.merchant_cert_status == 2"></image>
				</view>
			</view>
		</view>
		<view class="other-info">
			<view class="report-person">{{info?.enroll_num}}人报名</view>
			<view class="menu-desc">
				<view class="no-people" v-if="!info?.price_level || JSON.parse(info?.price_level) == false">不限</view>
				<template v-if="info?.price_level">
					<view class="price-list" v-for="(item,index) in JSON.parse(info.price_level)" :key="index">
						<text>¥{{ item.price }}</text>
						<text v-if="index+1 < (JSON.parse(info.price_level).length)">/</text>
					</view>
				</template>
				<!-- <view class="line"></view> -->
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			info: {
				type: Object,
				default() {
					return {}
				}
			}
		},
		emits: ['detail'],
		data() {
			return {
				
			}
		},
		computed: {
			priceMeal() {
				return JSON.parse(this.info?.price_level) || []
			}
		},
		methods: {
			detail() {
				const { id } = this.info
				uni.navigateTo({
					url: '/pages/detail/index?activityId='+id
				})
				this.$emit('detail')
			},
			statusFormat(status, start, end) {
				switch (status){
					case 1:
						const now = new Date().getTime()
						const	s = new Date(start?.replace(/\-/g,'/')).getTime(),
							e = new Date(end?.replace(/\-/g,'/')).getTime()
						if (s <= now && e >= now) {
							return '报名进行中'
						} else {
							return '进行中'
						}						
						break;
					case 2:
						return '报名进行中'
						break;
					case 3:
						return '报名结束'
						break;
					case 4:
						return '已取消'
						break;
					case 5:
						return '审核中'
						break;
					case 6:
						return '审核未通过'
						break;
					case 7:
						return '活动进行中'
						break;
					case 8:
						return '活动已结束'
						break;
				}
			},
			dateContrast(date1, date2, isOpenEqual = true) {
				let d2 = ''
				if (!date2) {
					d2 = new Date().getTime()
				}
				const d1 = new Date(date1).getTime()
				if (isOpenEqual) {
					return d1 >= d2 ? true : false
				} else {
					return d1 > d2 ? true : false
				}
			},
			activityDateFormat(startDate, endDate) {
				if (!startDate) {
					return '不限'
				}
				const s = startDate?.substring(0, startDate?.lastIndexOf(':')).replace(/\-/g, '.'),
					e = endDate?.substring(0, endDate?.lastIndexOf(':')).replace(/\-/g, '.')
				return `${s}～${e}`
			}
 		}
	}
</script>

<style scoped lang="scss">
	.activity-list-wrapper {
		background-color: #fff;
		position: relative;
		padding: 24rpx;
		border-radius: 24rpx;
		margin-bottom: 16rpx;
		
		.tag {
			position: absolute;
			left: 0;
			top: 0;
			height: 42rpx;
			min-width: 120rpx;
			padding: 0 16rpx;
			line-height: 42rpx;
			text-align: center;
			font-size: 22rpx;
			font-weight: 500;
			color: #fff;
			background: linear-gradient(to right, #FFDA43, #FFA437);
			border-radius: 20rpx 0 12rpx 0;
		}
		.tag-gray {
			background: #ddd;
			color: #666;
		}
	}
	
	.main-info {
		display: flex;
		
		.left {
			width: 180rpx;
			height: 240rpx;
			background-color: #f6f7f8;
			border-radius: 16rpx;
			overflow: hidden;
			&_img {
				width: 100%;
				height: 100%;
				border-radius: 16rpx;
			}
		}
		.right {
			width: calc(100% - 180rpx);
			padding-left: 20rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			.right-top {
				width: 100%;
			}
			.title {
				font-size: 30rpx;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				line-clamp: 2;
				-webkit-line-clamp: 2;
				overflow: hidden;
				font-weight: 500;
				margin-bottom: 16rpx;
			}
			.right-item {
				width: 100%;
				display: flex;
				align-items: center;
				padding: 6rpx 0;
				color: #666;
				font-size: 24rpx;
				.name {
					padding-left: 8rpx;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					text-overflow: ellipsis;
					line-clamp: 1;
					-webkit-line-clamp: 1;
					overflow: hidden;
					max-width: calc(100% - 32rpx);
				}
				.shop-auth {
					width: 30rpx;
					height: 30rpx;
					margin-left: 8rpx;
				}
				.time-text {
					line-clamp: 2;
					-webkit-line-clamp: 2;
					font-size: 23rpx;
				}
				.icon-img {
					width: 32rpx;
					height: 32rpx;
				}
				.avatar {
					width: 40rpx;
					height: 40rpx;
					border-radius: 50%;
					background-color: #eee;
				}
			}
			.time-wrapper {
				align-items: flex-start;
			}
		}
	}

	.other-info {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 30rpx;
		.report-person {
			font-size: 28rpx;
			color: #999;
		}
		.menu-desc {
			font-size: 30rpx;
			font-weight: bold;
			position: relative;
			display: flex;
			align-items: center;
			.price-list {
				color: $uni-color-primary;
				position: relative;
				z-index: 2;
			}
			.no-people {
				position: relative;
				z-index: 2;
				color: $uni-color-primary;
			}
			&::after {
				position: absolute;
				content: '';
				height: 16rpx;
				border-radius: 8rpx;
				background-color: #DDFFFD;
				bottom: 0;
				left: 0;
				right: 0;
				// z-index: 0;
			}
		}
	}
</style>